package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.HashMap;

/**
 * @author pengq
 */
@Getter
@Setter
public class StrategyComment extends BaseDomain {
    /**
     * 普通
     */
    public static final int STATE_COMMON = 0;
    /**
     * 热门
     */
    public static final int STATE_HOT = 1;
    /**
     * 禁用
     */
    public static final int STATE_DISABLE = -1;
    /**
     * 点评用户
     */
    private User user;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT-8")
    private Date createTime;
    /**
     * 评论内容
     */
    private String content;
    /**
     * 评论图片
     */
    private String imgUrls;
    /**
     * 星星数
     */
    private Integer starNum;
    /**
     * 对应的大攻略
     */
    private Strategy strategy;
    /**
     * 评论状态
     */
    private Integer state = STATE_COMMON;
    /**
     * 推荐时间
     */
    private Date commendTime;
    /**
     * 点赞数
     */
    private Integer love =0;


    /**
     * 通过切割取出每张评论图片地址
     *
     * @return
     */
    public String[] getImgUrlsArr() {
        if (StringUtils.hasLength(imgUrls)) {
            return imgUrls.split(";");
        }
        return null;
    }

    /**
     * 返回json数据
     * @return
     */
    public String getJson() {
        HashMap<String, Object> map = new HashMap<>(10);
        map.put("id", id);
        if(user != null){
            map.put("userName", user.getNickName());
        }
        map.put("imgArr", getImgUrlsArr());
        map.put("state", state);
        map.put("content", content);
        return JSON.toJSONString(map);
    }

    /**
     * 状态对应的文字
     *
     * @return
     */
    public String getStateName() {
        if (state == STATE_HOT) {
            return "热门";
        } else if (state == STATE_DISABLE) {
            return "禁用";
        } else {
            return "普通";
        }
    }

    /**
     * 星星数对应的图案
     */
    public String getStarImg() {
        if (starNum == 1) {
            return "★☆☆☆☆";
        } else if (starNum == 2) {
            return "★★☆☆☆";
        } else if (starNum == 3) {
            return "★★★☆☆";
        } else if (starNum == 4) {
            return "★★★★☆";
        } else {
            return "★★★★★";
        }
    }
}